#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>

using namespace std;

double qmi(double x, int n)
{
    double res = 1;
    while (n)
    {
        if (n & 1)
            res *= x;
        n >>= 1;
        x *= x;
    }
    return res;
}
double myPow(double x, int n) {
    if (n < 0)
    {
        x = 1 / x;
        n = abs(n);
    }
    return qmi(x, n);
}

void dfs(int u, int k, vector<int>& path, vector<vector<int>>& graph, vector<vector<int>>& res, vector<bool>& st)
{
    if (u == k)
    {
        res.push_back(path);
        return;
    }
    for (auto next : graph[u])
    {
        if (st[next])    continue;
        st[next] = true;
        path.push_back(next);
        dfs(next, k, path, graph, res, st);
        path.pop_back();
        st[next] = false;
    }
}

vector<vector<int>> allPathsSourceTarget(vector<vector<int>>& graph) {
    int n = graph.size();
    vector<vector<int>> res;
    vector<bool> st(n);
    vector<int> path(1);
    dfs(0, n - 1, path, graph, res, st);
    return res;
}

int main()
{
    vector<vector<int>> vv = { {1,2},{3},{3},{} };
    allPathsSourceTarget(vv);
    return 0;
}